(function($) {
    $(function(){
        $('#J_records').removeClass('dn');

        new Vue({
            el: '#J_records',
            data: function() {
                return {
                    total: '0.00',
                    list: [],
                    date: '',
                    is_first_request: true
                }
            },
            watch: {
                date: function(newDate, oldDate) {
                    if (!this.is_first_request) {
                        this.getList(newDate)
                    }                  
                }
            },
            created: function() {    
                var myDate=new Date()
                this.date = myDate.getFullYear() + '-' + (myDate.getMonth()*1 + 1)
                this.getList('')
            },
            mounted: function() {
                const _this = this;
                new Mdate("dateSelectorOne", {
                    acceptId: "dateSelect",
                    beginYear: '2017',
                    format: "-",
                    vm: _this
                })
            },
            methods: {
                getList: function(date) {
                    const _this = this;
                    var shop_id = $.getQueryString('shop_id') || ''
                    $.mAjax({
                        url: '/order/get-cancel-list-by-myself',
                        data: {cancel_time: date, shop_id: shop_id},
                        success: function(res) {
                            if(res.status == 1) {
                                _this.list = res.data.list
                                _this.total = res.data.total
                            } else {
                                if (res.error.errorno == '401') {
                                    layer.open({
                                        content: '登录过期，请重新登录！',
                                        skin: 'msg',
                                        time: 2 //2秒后自动关闭
                                    })
                                    setTimeout(function () {
                                        localStorage.removeItem('_u_info_')
                                        location.href = './index.html'
                                    }, 2000)
                                }
                            }
                            _this.is_first_request = false
                        }
                    })
                }
            },
            filters: {
                hide: function (tel) {
                    return tel ? tel.substr(0, 3) + '****' + tel.substr(7, 11) : ''
                },
                format: function(time) {
                    return time.split(' ')[0]
                }
            }
        })
    })    
})(jQuery)